import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(
    home: Scaffold(
      appBar: AppBar(
        title: const Text("Transform Widget Demo"),
      ),
      body: CustomClipWidget(),
    ),
  ));
}

class CustomClipWidget extends StatelessWidget {
  const CustomClipWidget({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        children: [
          wContainer(BoxFit.none),
          const Text("Hello World"),
          wContainer(BoxFit.contain),
          const Text("Flutter 中国"),
        ],
      ),
    );
  }

  Widget wContainer(BoxFit boxFit) {
    return ClipRect(
      //将超出子组件布局范围得绘制内容裁剪掉
        child: Container(
          width: 50,
          height: 50,
          color: Colors.red,
          child: FittedBox(
            fit: boxFit,
            //  子容器超过父容器
            child: Container(
              width: 60,
              height: 70,
              color: Colors.blue,
            ),
          ),
        ));
  }
}